/*
 * Created on Jul 18, 2006
 */
package net.amsoft.iservice.management.webapp.struts.action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.amsoft.iservice.management.service.IBrokerManagerService;
import net.amsoft.iservice.management.util.IBrokerConstants;
import net.amsoft.iservice.util.IServiceConstants;
import net.amsoft.iservice.util.IServiceUtil;
import net.amsoft.iservice.util.exception.IServiceException;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * First action to be called whenever a user hits the IServices Manager 
 * Application URL. Fetches the list of all the IBrokers and lists of 
 * the IServices hosted by every IBroker <br>
 * 
 * @author mukta
 */
public class InitializeAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception 
	{
        IServiceUtil.log(IServiceConstants.INFO, this, "execute(): entry");

		// Set ISSOBrokers
		try {
			ArrayList oISSOBrokers = IBrokerManagerService.getAllIBrokers(IBrokerConstants.getProperty(IBrokerConstants.SERVICE_ISSO));
			request.getSession().setAttribute("ISSOBrokers", oISSOBrokers);
		} catch (IServiceException e) {
			request.getSession().setAttribute("ISSOBrokers", null);
		}
        IServiceUtil.log(IServiceConstants.INFO, this, "execute(): ISSOBrokers=" + 
        		request.getSession().getAttribute("ISSOBrokers"));
		
		// Set ILinkBrokers
		try {
			ArrayList oILinkBrokers = IBrokerManagerService.getAllIBrokers(IBrokerConstants.getProperty(IBrokerConstants.SERVICE_ILINK));
			request.getSession().setAttribute("ILinkBrokers", oILinkBrokers);
		} catch (IServiceException e) {
			request.getSession().setAttribute("ILinkBrokers", null);
		}
        IServiceUtil.log(IServiceConstants.INFO, this, "execute(): ILinkBrokers=" + 
        		request.getSession().getAttribute("ILinkBrokers"));
		
		// Set IContactBrokers
		try {
			ArrayList oIContactBrokers = IBrokerManagerService.getAllIBrokers(IBrokerConstants.getProperty(IBrokerConstants.SERVICE_ICONTACT));
			request.getSession().setAttribute("IContactBrokers", oIContactBrokers);
		} catch (IServiceException e) {
			request.getSession().setAttribute("IContactBrokers", null);
		}
        IServiceUtil.log(IServiceConstants.INFO, this, "execute(): IContactBrokers=" + 
        		request.getSession().getAttribute("IContactBrokers"));
		
        IServiceUtil.log(IServiceConstants.INFO, this, "execute(): redirect to=" + 
        		IBrokerConstants.FWD_SUCCESS);
		return mapping.findForward(IBrokerConstants.FWD_SUCCESS);
	}
}
